package com.caifu.time;

import com.caifu.pojo.CDevice;
import com.caifu.service.ActiveMqService;
import com.caifu.service.UserDeviceService;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Component
public class DoorOrderTimer {

    @Resource
    private ActiveMqService activeMqService;
    @Resource
    private UserDeviceService userDeviceService;


    /**
     * 人员信息同步至下发列表
     */
    @Scheduled(cron="0 0/15 * * * ?")
    @PostConstruct  //项目启动时候执行一次
    public void addDeviceRecord(){
        //获取AccessToken
        try {
            //查询未同步的cdUser列表
            Map map = userDeviceService.listDeviceUser();
            System.out.println(map);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }


    /**
     * 人员信息下发
     */
    @Scheduled(cron="0 0/15 * * * ?")
    @PostConstruct  //项目启动时候执行一次
    public void addDoorOrder(){
        //获取AccessToken
        try {
            List<CDevice> list = userDeviceService.listDevive();
            for (CDevice device : list) {
                Map map = activeMqService.addMqMessage(device.getId()+"");
                System.out.println(map);
            }

        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }




}
